package cn.lingyangwl.agile.msg.push.listener;

import cn.lingyangwl.framework.mq.base.manager.MqManager;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import cn.lingyangwl.agile.msg.push.api.constatnts.MsgPushMqCons;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Slf4j
@Component
@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue(value = MsgPushMqCons.MSG_PUSH_ERROR_QUEUE, durable = "true"), key = MsgPushMqCons.MSG_PUSH_ERROR_KEY,
                exchange = @Exchange(value = MsgPushMqCons.MSG_PUSH_ERROR_EXCHANGE, type = ExchangeTypes.TOPIC))
})
public class PushErrorListener {
    @Resource
    private MqManager mqManager;

    @RabbitHandler
    public void onMessage(String data, Channel channel, Message message) {
        try {
            log.info("消费成功-告警发送短信: {}", data);
        } catch (Exception e) {
            log.error("消费失败: {}", e.getMessage());
            throw new BizException(-1, "mq消费失败");
        }
    }
}
